package dev.ece.suit.loader.models.ms3d;

import java.io.IOException;

import dev.ece.util.io.LittleEndianInputStream;

/**
 * 组
 * @author 飘渺青衣
 * <b>E-mail：</b>3375758@qq.com
 */
public class MS3DGroup {

	private String name;
	
	private int[] indice;
	
	private byte materialIndex;
	
	private String comment;
	
	private MS3DGroup() {}
	
	public static MS3DGroup[] load(LittleEndianInputStream is) throws IOException {
		MS3DGroup[] groups = new MS3DGroup[is.readUnsignedShort()];
		MS3DGroup group = null;
		for(int i=0; i<groups.length; i++) {
			groups[i] = group = new MS3DGroup();
			is.skip(1);
			group.name = is.readString(32);
			group.indice = new int[is.readUnsignedShort()];
			for(int j=0; j<group.indice.length; j++) {
				group.indice[j] = is.readUnsignedShort();
			}
			group.materialIndex = is.readByte();
		}
		return groups;
	}
	
	public static void loadComment(LittleEndianInputStream is, MS3DGroup[] groups) throws IOException {
		int count = is.readInt();
		MS3DGroup group = null;
		long commentSize = 0;
		for(int i=0; i<count; i++) {
			group = groups[is.readInt()];
			commentSize = is.readUnsignedInt();
			if(commentSize > 0) {
				group.comment = is.readString((int) commentSize);
			}
		}
	}
	
	public String getName() {
		return name;
	}

	public int[] getIndice() {
		return indice;
	}

	public byte getMaterialIndex() {
		return materialIndex;
	}

	public String getComment() {
		return comment;
	}

}
